import { useEffect, useState } from "react";

export default function usePosition() {
    let [x, setX] = useState(100);
    let [y, setY] = useState(100);
    function move(e) {
        console.log('e: ', e.clientX, e.clientY);
        setX(e.clientX);
        setY(e.clientY);
    }
    useEffect(() => {//componentDidMount
        // 绑定自定事件
        window.addEventListener('mousemove', move)
        return () => {
            window.removeEventListener('mousemove', move)
        }
    }, [])
    return {x,y}
}